package com.leonzhangxf.xml.custom;

import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;

import java.text.SimpleDateFormat;

/**
 * {@link SimpleDateFormat}类定义解析器
 *
 * @author leonzhangxf
 * @date 20190603
 */
public class LeonUtilsLeonPinterBeanDefinitionParser extends AbstractSimpleBeanDefinitionParser {

    @Override
    protected Class<?> getBeanClass(Element element) {
        return LeonPrinter.class;
    }

    @Override
    protected void doParse(Element element, BeanDefinitionBuilder bean) {
        String msg = element.getAttribute("msg");
        if (!StringUtils.hasText(msg)) {
            throw new LeonUtilsLeonPinterParseException("The msg parameter of com.leonzhangxf.xml.custom.LeonPrinter"
                + " could not be empty.");
        }

        String print = element.getAttribute("print");
        if (StringUtils.hasText(print)) {
            bean.addPropertyValue("print", Boolean.valueOf(msg));
        }
    }
}
